package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteAttachmentService;
import com.ruoyi.system.api.domain.Attachment;
import com.ruoyi.system.api.domain.AttachmentVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteAttachmentFallbackFactory implements FallbackFactory<RemoteAttachmentService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteAttachmentFallbackFactory.class);

    @Override
    public RemoteAttachmentService create(Throwable throwable)
    {
        log.error("附件关联信息服务调用失败:{}", throwable.getMessage());
        return new RemoteAttachmentService()
        {
            @Override
            public R add(Attachment attachment) {
                return  R.fail("上传附件关联信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> batchAdd(AttachmentVO vo, String source) {
                return  R.fail("批量更新附件关联失败:" + throwable.getMessage());
            }

            @Override
            public R batchDeleteAttachment(List<Long> associatedIds, String source) {
                return  R.fail("批量删除附件失败:" + throwable.getMessage());
            }

            @Override
            public R getPictureByAssociatedId(Long associatedId, String source) {
                return  R.fail("获取附件信息失败:" + throwable.getMessage());
            }

        };
    }
}
